/***********09-15-新加tab*********** */
const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cameras:[],
    regions: [],
    regionId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.queryAllCanear()
    this.getRegions();
  },
  changeRegion:function(e){
    //console.log(JSON.stringify(e.target.id));
    //console.log(e.target.id == 0);
    if(e.target.id == 0){
      this.setData({
        regionId: ''
      });
    }else{
      this.setData({
        regionId: e.target.id
      });
    }
    
    this.queryAllCanear();
  },
  getRegions: function () {
    var that = this;
    util.request(api.RegionList,{'regionId':this.data.regionId}).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          regions: res.data.list
        });
      }

    });
  },
  toCamera(e){
    var param = e.currentTarget.dataset;
    var id = param['id'];
    //console.log(id);
    wx.navigateTo({
      url: '../../living/liv?id=' + id
    })



  },
  queryAllCanear(){
    //console.log('vvvvvvvvvvvvv');schoolCaneraUrl
    var that = this;
    util.request(api.schoolCaneraUrl, {'regionId':this.data.regionId}).then(function (res) {
      //console.log(JSON.stringify(res.data));
      that.setData({
        cameras:res.data
      })
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})